#include "page4.h"


page4::page4(QWidget* parent)
	: QWidget(parent)
{
	this->setWindowIcon(QIcon("Image\\运动会.svg"));
	QPixmap pixmap("Image\\光标.svg");
	//pixmap.scaled(40, 30, Qt::KeepAspectRatio, Qt::SmoothTransformation);
	pixmap = pixmap.scaled(30, 24, Qt::KeepAspectRatio);
	QCursor cursor(pixmap);
	this->setCursor(cursor);

	this->parent = dynamic_cast<SportMeeting*>(parent);
	ui.setupUi(this);
	ui.totaltable->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter);//表头字体居中
	connect(ui.pre_page, &QPushButton::clicked, this, &page4::pre_page);
	connect(ui.next_page, &QPushButton::clicked, this, &page4::next_page);
	connect(ui.typeBox, &QComboBox::currentIndexChanged, this, &page4::typeBox);
	connect(ui.waysBox, &QComboBox::currentIndexChanged, this, &page4::waysBox);
	connect(ui.sortButton, &QPushButton::clicked, this, &page4::sort);
	connect(ui.checkButton,&QPushButton::clicked,this,&page4::check);
}

page4::~page4()
{

}

void page4::initRowlabels() {

}
void page4::initColumnlabels() {

}
void page4::exchange(QString m,QString n) {
	QString temp;
	temp = m;
	n = m;
	m = temp;
}


void page4::updatalabels() {
	rowlabels.clear();
	columnlabels.clear();
	int row = this->myData->getTeamNum();
	int column1 = this->myData->getItemNum1();
	int column2 = this->myData->getItemNum2();
	int totalcolumn = column1 + column2;
	for (int i = 0;i <= totalcolumn;i++) {
		columnlabels << ui.totaltable->horizontalHeaderItem(i)->text();
	}
	for (int i = 0;i <row;i++) {
		rowlabels << ui.totaltable->verticalHeaderItem(i)->text();
	}
	ui.totaltable->setVerticalHeaderLabels(rowlabels);
	ui.totaltable->setHorizontalHeaderLabels(columnlabels);
}

void page4::initTable() {
	int row = this->myData->getTeamNum();
	int column1 = this->myData->getItemNum1();
	int column2 = this->myData->getItemNum2();
	int column = column1 + column2;
	matrix.clear();
	//初始化表格
	for (int i = 0;i < row;i++) {
		matrix.append(QVector<int>());
	}
	for (int i=0;i < row;i++) {
		for (int j = 0;j < column;j++) {
			matrix[i].append(teams[i].getVal()[j]);
		}
	}
	reallyRow.clear();
	reallyColumn.clear();
	//初始化两个记录数组
	for (int i = 0;i < row;i++) {
		reallyRow.push_back(i);
	}
	for (int i = 0;i < column;i++) {
		reallyColumn.push_back(i);
	}
	//设置标签值
	columnlabels.clear();
	rowlabels.clear();
	for (int i = 0; i < boyItems.size(); i++) {
		columnlabels.append(boyItems[i].getName());
	}
	for (int i = 0; i < girlItems.size(); i++) {
		columnlabels.append(girlItems[i].getName());
	}
	columnlabels.append("总分");
	ui.totaltable->setHorizontalHeaderLabels(columnlabels);
	for (int i = 0;i < teams.size();i++) {
		rowlabels.append(teams[i].getName());
	}
	ui.totaltable->setVerticalHeaderLabels(rowlabels);
	//给单元格设置初始值
	ui.totaltable->setColumnCount(column + 1);
	ui.totaltable->setRowCount(row);
	for (int i = 0; i < row; i++)
	{
		int* itemval = teams[i].getVal();
		int total = 0;
		for (int j = 0; j < column; j++)
		{
			int value = *(itemval + j);
			total += value;
			QString strVal = QString::number(value);
			QTableWidgetItem* item = ui.totaltable->item(i, j);
			if (item == nullptr) {
				item = new QTableWidgetItem();
				ui.totaltable->setItem(i, j, item);
			}
			ui.totaltable->item(i, j)->setText(strVal);
			ui.totaltable->item(i, j)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		}
		QTableWidgetItem* item = ui.totaltable->item(i, column);
		if (item == nullptr) {
			item = new QTableWidgetItem();
			ui.totaltable->setItem(i, column, item);
		}
		//设置总分，并存于teams[i]中的val数组中
		teams[i].setVal(column, total);
		matrix[i].append(teams[i].getVal()[column]);
		QString strTotal = QString::number(total);
		ui.totaltable->item(i, column)->setText(strTotal);
		ui.totaltable->item(i, column)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		itemval = nullptr;
	}
}

void page4::setData(MyData* data) {
	this->myData = data;
}
void page4::loadData() {
	int row = this->myData->getTeamNum();
	int column1 = this->myData->getItemNum1();
	int column2 = this->myData->getItemNum2();
	int column = column1 + column2;
	//导入数组
	for (int i = 0;i < column1;i++) {
		boyItems.append(this->myData->getBoyItems()[i]);
	}
	for (int i = 0;i < column2;i++) {
		girlItems.append(this->myData->getGirlItems()[i]);
	}
	for (int i = 0;i < row;i++) {
		teams.append(this->myData->getTeams()[i]);
	}
	//初始化记录数组以及初始表格
	initTable();
	//设置Combobox的标签
	ui.waysBox->clear();
	ui.typeBox->clear();
	ui.typeBox->addItem("默认");
	ui.typeBox->addItem("队伍");
	ui.typeBox->addItem("男生项目");
	ui.typeBox->addItem("女生项目");
	ui.typeBox->addItem("总分");

	
}



//槽函数
void page4::pre_page() {
	setPage(parent, parent->pageThree);
}
void page4::next_page() {
	parent->pageFive->setData(myData);
	parent->pageFive->loadData();
	setPage(parent, parent->pageFive);
}
//相应类型排序关键词
void page4::typeBox() {
	int row = this->myData->getTeamNum();
	int column1 = this->myData->getItemNum1();
	int column2 = this->myData->getItemNum2();
	//vector<boyItem>& boyItems = this->myData->getBoyItems();
	//vector<girlItem>& girlItems = this->myData->getGirlItems();
	//vector<team>& teams = this->myData->getTeams();
	QVector<boyItem>& boyItems = this->myData->getBoyItems();
	QVector<girlItem>& girlItems = this->myData->getGirlItems();
	QVector<team>& teams = this->myData->getTeams();
	QString tempName = ui.typeBox->currentText();
	ui.waysBox->clear();
	for (int i = 0;i < row;i++) {
		ui.totaltable->setRowHidden(i, 0);
	}
	for (int i = 0;i < column1+column2+1;i++) {
		ui.totaltable->setColumnHidden(i, 0);
	}
	if (tempName == "队伍") {
		for (int i = 0;i < row;i++) {
			ui.waysBox->addItem(teams[i].getName());
		}
	}
	else if (tempName == "男生项目") {
		for (int i = 0;i < column1;i++) {
			ui.waysBox->addItem(boyItems[i].getName());
		}
	}
	else if (tempName == "女生项目") {
		for (int i = 0;i < column2;i++) {
			ui.waysBox->addItem(girlItems[i].getName());
		}
	}
	else if(tempName == "总分"){
		ui.waysBox->addItem("总分");
	}
	else {
		ui.waysBox->addItem("默认");
		initTable();
	}
}
//相应方式排序关键词
void page4::waysBox() {
	int row = this->myData->getTeamNum();
	int column1 = this->myData->getItemNum1();
	int column2 = this->myData->getItemNum2();
	for (int i = 0;i < row;i++) {
		ui.totaltable->setRowHidden(i, 0);
	}
	for (int i = 0;i < column1 + column2+1;i++) {
		ui.totaltable->setColumnHidden(i, 0);
	}
}
//排序
void page4::sort() {
	int row = this->myData->getTeamNum();
	int column1 = this->myData->getItemNum1();
	int column2 = this->myData->getItemNum2();
	int totalcolumn = column1 + column2;
	//vector<boyItem> boyItems = this->myData->getBoyItems();
	//vector<girlItem> girlItems = this->myData->getGirlItems();
	//vector<team> teams = this->myData->getTeams();
	QString tempName1 = ui.typeBox->currentText();//类型
	QString tempName2 = ui.waysBox->currentText();

	if (tempName1 == "队伍") {
		//寻找目标排序队伍
		int sortIndex = 0;
		for (int i = 0;i < row;i++) {
			if (teams[i].getName() == tempName2) {
				sortIndex = i;
				break;
			}
		}
		//拿取目标排序队伍的得分值降序后，索引放入sortitem
		int* itemval = teams[sortIndex].getVal();
		
		for (int i = 0; i < totalcolumn - 1; i++) {
			bool swapped = false;
			for (int j = 0; j < totalcolumn - i - 1; j++) {
				if (itemval[reallyColumn[j]] < itemval[reallyColumn[j + 1]]) {
					for (int k = 0;k < row;k++) {
						swap(matrix[k][j],matrix[k][j + 1]);
					}
					swap(reallyColumn[j], reallyColumn[j + 1]);
					swapped = true;
				}
			}
			if (!swapped) break; 
		}
		//设置标签值
		
		columnlabels.clear();
		for (int i = 0; i < totalcolumn; ++i) {
			if (reallyColumn[i] < column1) {
				QString temp = boyItems[reallyColumn[i]].getName();
				columnlabels.append(temp);
			}
			else {
				QString temp = girlItems[reallyColumn[i]-column1].getName();
				columnlabels.append(temp);
			}
		}
		columnlabels.append("总分");
		ui.totaltable->setHorizontalHeaderLabels(columnlabels);
		//对显示的值进行改变
		for (int k = 0;k < row;k++) {
			for (int i = 0;i < totalcolumn;i++) {
				/*if (sortitem[i] >= column1) {
					QString str= QString::number(itemval[sortitem[i]]);
					ui.totaltable->item(k, i)->setText(str);
				}
				else {
					QString str = QString::number(itemval[sortitem[i]]);
					ui.totaltable->item(k, i)->setText(str);
				}*/
				QString str = QString::number(matrix[k][i]);
				ui.totaltable->item(k, i)->setText(str);
				ui.totaltable->item(k, i)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
			}
			QString str = QString::number(matrix[k][totalcolumn]);
			ui.totaltable->item(k, totalcolumn)->setText(str);
			ui.totaltable->item(k, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		}
		
		//int* itemVal =nullptr;
		//for (int i = 0;i < row;i++) {
		//	if (tempName2 == teams[i].getName()) {
		//		itemVal = teams[i].getVal();
		//		break;
		//	}
		//}
		//for (int i = 0; i < totalcolumn - 1; i++) {
		//	bool swapped = false;
		//	for (int j = 0; j < totalcolumn - i - 1; j++) {
		//		if (itemVal[j] < itemVal[j+1]) {
		//			for (int k = 0;k < row;k++) {
		//				int* tempVal = teams[k].getVal();
		//				swap(tempVal[j], tempVal[j + 1]);
		//			}
		//			swap(columnlabels[j],columnlabels[j+1]);
		//			swapped = true;
		//		}
		//	}
		//	if (!swapped) break; 
		//}
		////设置标签值
		//ui.totaltable->setHorizontalHeaderLabels(columnlabels);
		////显示文本值
		//for (int k = 0;k < teams.size();k++) {
		//	int* itemval = teams[k].getVal();
		//	for (int i = 0;i < totalcolumn;i++) {
		//		/*if (sortitem[i] >= column1) {
		//			QString str= QString::number(itemval[sortitem[i]]);
		//			ui.totaltable->item(k, i)->setText(str);
		//		}
		//		else {
		//			QString str = QString::number(itemval[sortitem[i]]);
		//			ui.totaltable->item(k, i)->setText(str);
		//		}*/
		//		QString str = QString::number(itemval[i]);
		//		ui.totaltable->item(k, i)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//	}
		//	QString str = QString::number(itemval[totalcolumn]);
		//	ui.totaltable->item(k, totalcolumn)->setText(str);
		//	ui.totaltable->item(k, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//	itemval = nullptr;
		//}
	}
	else if (tempName1 == "男生项目") {
		//寻找目标排序项目
		int sortIndex = 0;
		for (int i = 0;i < row;i++) {
			if (boyItems[i].getName() == tempName2) {
				sortIndex = i;
				break;
			}
		}
		//根据目标排序项目的得分值降序后，索引放入sortitem
		int* itemRank = boyItems[sortIndex].getRank();
		
		for (int i = 0; i < row - 1; i++) {
			bool swapped = false;
			for (int j = 0; j < row - i - 1; j++) {
				if (itemRank[reallyRow[j]] > itemRank[reallyRow[j + 1]]) {
					swap(matrix[j], matrix[j + 1]);
					swap(reallyRow[j], reallyRow[j + 1]);
					swapped = true;
				}
			}
			if (!swapped) break;
		}
		
		//设置标签的值
		rowlabels.clear();
		for (int i = 0; i < row; ++i) {
			rowlabels.append(teams[reallyRow[i]].getName());
		}
		ui.totaltable->setVerticalHeaderLabels(rowlabels);
		//对显示的值进行改变
		for (int k = 0;k < teams.size();k++) {
			for (int i = 0;i < totalcolumn;i++) {
				QString str = QString::number(matrix[k][i]);
				ui.totaltable->item(k, i)->setText(str);
				ui.totaltable->item(k, i)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
			}
			QString strtotal = QString::number(matrix[k][totalcolumn]);
			ui.totaltable->item(k, totalcolumn)->setText(strtotal);
			ui.totaltable->item(k, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		}
		
		//int* itemRank = nullptr;
		//for (int i = 0;i < totalcolumn;i++) {
		//	if (tempName2 == boyItems[i].getName()) {
		//		itemRank = boyItems[i].getRank();
		//		break;
		//	}
		//}
		//for (int i = 0; i < row - 1; i++) {
		//	bool swapped = false;
		//	for (int j = 0; j < row - i - 1; j++) {
		//		if (itemRank[j] > itemRank[j + 1]) {
		//			for (int k = 0;k < totalcolumn;k++) {
		//				
		//			}
		//			teams[totalcolumn]
		//			exchange(columnlabels[j], columnlabels[j + 1]);
		//			swapped = true;
		//		}
		//	}
		//	if (!swapped) break;
		//}
		////设置标签值
		//ui.totaltable->setHorizontalHeaderLabels(columnlabels);
		////显示文本值
		//for (int k = 0;k < teams.size();k++) {
		//	int* itemval = teams[k].getVal();
		//	for (int i = 0;i < totalcolumn;i++) {
		//		/*if (sortitem[i] >= column1) {
		//			QString str= QString::number(itemval[sortitem[i]]);
		//			ui.totaltable->item(k, i)->setText(str);
		//		}
		//		else {
		//			QString str = QString::number(itemval[sortitem[i]]);
		//			ui.totaltable->item(k, i)->setText(str);
		//		}*/
		//		QString str = QString::number(itemval[i]);
		//		ui.totaltable->item(k, i)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//	}
		//	QString str = QString::number(itemval[totalcolumn]);
		//	ui.totaltable->item(k, totalcolumn)->setText(str);
		//	ui.totaltable->item(k, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//	itemval = nullptr;
		//}
	}
	else if (tempName1 == "女生项目") {
		//int sortIndex = 0;
		//for (int i = 0;i < row;i++) {
		//	if (girlItems[i].getName() == tempName2) {
		//		sortIndex = i;
		//		break;
		//	}
		//}
		////根据目标排序项目的得分值降序后，索引放入sortitem
		//int* itemRank = girlItems[sortIndex].getRank();
		//vector<int> sortitem(row, 0);
		//for (int i = 0; i < row; ++i) {
		//	sortitem[i] = i;
		//}
		//for (int i = 0; i < row - 1; i++) {
		//	bool swapped = false;
		//	for (int j = 0; j < row - i - 1; j++) {
		//		if (itemRank[sortitem[j]] > itemRank[sortitem[j + 1]]) {
		//			swap(sortitem[j], sortitem[j + 1]);
		//			swapped = true;
		//		}
		//	}
		//	if (!swapped) break;
		//}
		////设置标签的值
		//rowlabels.clear();
		//for (int i = 0; i < row; ++i) {
		//	rowlabels.append(teams[sortitem[i]].getName());
		//}
		//ui.totaltable->setVerticalHeaderLabels(rowlabels);
		////对显示的值进行改变
		//for (int k = 0;k < teams.size();k++) {
		//	int* itemval = teams[sortitem[k]].getVal();
		//	for (int i = 0;i < totalcolumn;i++) {
		//		QString str = QString::number(itemval[i]);
		//		ui.totaltable->item(k, i)->setText(str);
		//		ui.totaltable->item(k, i)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//	}
		//	QString strtotal = QString::number(itemval[totalcolumn]);
		//	ui.totaltable->item(k, totalcolumn)->setText(strtotal);
		//	ui.totaltable->item(k, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//	itemval = nullptr;
		//}
		//寻找目标排序项目
		int sortIndex = 0;
		for (int i = 0;i < row;i++) {
			if (girlItems[i].getName() == tempName2) {
				sortIndex = i;
				break;
			}
		}
		//根据目标排序项目的得分值降序后，索引放入sortitem
		int* itemRank = girlItems[sortIndex].getRank();

		for (int i = 0; i < row - 1; i++) {
			bool swapped = false;
			for (int j = 0; j < row - i - 1; j++) {
				if (itemRank[reallyRow[j]] > itemRank[reallyRow[j + 1]]) {
					swap(matrix[j], matrix[j + 1]);
					swap(reallyRow[j], reallyRow[j + 1]);
					swapped = true;
				}
			}
			if (!swapped) break;
		}
		//设置标签的值
		rowlabels.clear();
		for (int i = 0; i < row; ++i) {
			rowlabels.append(teams[reallyRow[i]].getName());
		}
		ui.totaltable->setVerticalHeaderLabels(rowlabels);
		//对显示的值进行改变
		for (int k = 0;k < teams.size();k++) {
			for (int i = 0;i < totalcolumn;i++) {
				QString str = QString::number(matrix[k][i]);
				ui.totaltable->item(k, i)->setText(str);
				ui.totaltable->item(k, i)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
			}
			QString strtotal = QString::number(matrix[k][totalcolumn]);
			ui.totaltable->item(k, totalcolumn)->setText(strtotal);
			ui.totaltable->item(k, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		}
	}
	else if (tempName1 == "总分") {
		
		//for (int i = 0; i < row - 1; i++) {
		//	bool swapped = false;
		//	for (int j = 0; j < row - i - 1; j++) {
		//		if (total[j] < total[j + 1]) {
		//			swap(total[j], total[j + 1]);
		//			swapped = true;
		//		}
		//	}
		//	if (!swapped) break;
		//}
		////引入排序数组
		//vector<int> sortitem(row, 0);//存降序的总分的队伍索引
		//vector<int> judge(row, 0);//判断数组，为0表示无对应，为1表示对应
		//for (int i = 0;i < row;i++) {
		//	for (int j = 0;j < row;j++) {
		//		int* itemval = teams[j].getVal();
		//		if ( itemval[totalcolumn] == total[i]&&judge[j]!=1) {
		//			sortitem[i]=j;
		//			judge[j] = 1;
		//			break;
		//		}
		//		itemval = nullptr;
		//	}
		//}
		////设置标签的值
		//
		////改变标签以及单元格值
		//QStringList labels;
		//for (int k = 0;k < teams.size();k++) {
		//	int* itemval = teams[sortitem[k]].getVal();
		//	labels.append(teams[sortitem[k]].getName());
		//	for (int i = 0;i < totalcolumn;i++) {
		//		QString str = QString::number(itemval[i]);
		//		ui.totaltable->item(k, i)->setText(str);
		//		ui.totaltable->item(k, i)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//	}
		//	QString strtotal = QString::number(itemval[totalcolumn]);
		//	ui.totaltable->item(k, totalcolumn)->setText(strtotal);
		//	ui.totaltable->item(k, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//	itemval = nullptr;
		//}
		//ui.totaltable->setVerticalHeaderLabels(labels);
		//labels.clear();
		//
		
		////读取所有总分放置于一个数组中
		//vector<int> total(row, 0);
		//for (int i = 0;i < row;i++) {
		//	QString str = ui.totaltable->item(i, totalcolumn)->text();
		//	total[i]=str.toInt();
		//}
		//根据目标排序项目的得分值降序后，索引放入sortitem
		
		for (int i = 0; i < row - 1; i++) {
			bool swapped = false;
			for (int j = 0; j < row - i - 1; j++) {
				if (matrix[j][totalcolumn] < matrix[j+1][totalcolumn]) {
					swap(reallyRow[j], reallyRow[j + 1]);
					swap(matrix[j], matrix[j + 1]);
					swapped = true;
				}
			}
			if (!swapped) break;
		}
		//设置标签的值
		rowlabels.clear();
		for (int i = 0; i < row; ++i) {
			rowlabels.append(teams[reallyRow[i]].getName());
		}
		ui.totaltable->setVerticalHeaderLabels(rowlabels);
		//对显示的值进行改变
		for (int k = 0;k < teams.size();k++) {
			for (int i = 0;i < totalcolumn;i++) {
				QString str = QString::number(matrix[k][i]);
				ui.totaltable->item(k, i)->setText(str);
				ui.totaltable->item(k, i)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
			}
			QString strtotal = QString::number(matrix[k][totalcolumn]);
			ui.totaltable->item(k, totalcolumn)->setText(strtotal);
			ui.totaltable->item(k, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		}
	}
	else {
		//	//设置行列的标签
		//	QStringList labels;
		//	for (int i = 0; i < boyItems.size(); i++) {
		//		labels.append(boyItems[i].getName());
		//	}
		//	for (int i = 0; i < girlItems.size(); i++) {
		//		labels.append(girlItems[i].getName());
		//	}
		//	labels.append("总分");
		//	ui.totaltable->setHorizontalHeaderLabels(labels);
		//	labels.clear();
		//	for (int i = 0;i < teams.size();i++) {
		//		labels.append(teams[i].getName());
		//	}
		//	ui.totaltable->setVerticalHeaderLabels(labels);
		//	//设置单元格的值
		//	
		//	for (int i = 0; i < row; i++)
		//	{
		//		int* itemval = teams[i].getVal();
		//		for (int j = 0; j < totalcolumn; j++)
		//		{
		//			int value = *(itemval + j);
		//			QString strVal = QString::number(value);
		//			QTableWidgetItem* item = ui.totaltable->item(i, j);
		//			if (item == nullptr) {
		//				item = new QTableWidgetItem();
		//				ui.totaltable->setItem(i, j, item);
		//			}
		//			ui.totaltable->item(i, j)->setText(strVal);
		//			ui.totaltable->item(i, j)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//		}
		//		QTableWidgetItem* item = ui.totaltable->item(i, totalcolumn);
		//		if (item == nullptr) {
		//			item = new QTableWidgetItem();
		//			ui.totaltable->setItem(i, totalcolumn, item);
		//		}
		//		//设置总分，并存于teams[i]中的val数组中
		//		QString strTotal = QString::number(itemval[totalcolumn]);
		//		ui.totaltable->item(i, totalcolumn)->setText(strTotal);
		//		ui.totaltable->item(i, totalcolumn)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
		//		itemval = nullptr;
		//	}
		//}
		initTable();
	}
}

//查找
void page4::check() {
	int row = this->myData->getTeamNum();
	int column1 = this->myData->getItemNum1();
	int column2 = this->myData->getItemNum2();
	int totalcolumn = column1 + column2;
	QString tempType = ui.typeBox->currentText();
	QString tempCheck = ui.checkEdit->text();
	//遍历一遍将所有解除隐藏
	for (int i = 0;i < row;i++) {
		ui.totaltable->setRowHidden(i, 0);
	}
	for (int i = 0;i < totalcolumn+1;i++) {
		ui.totaltable->setColumnHidden(i, 0);
	}
	//判断开始
	if (tempType == "总分") {
		for (int i = 0;i < totalcolumn;i++) {
			ui.totaltable->setColumnHidden(i, 1);
		}
		ui.totaltable->setColumnHidden(totalcolumn, 0);
	}
	else if (tempType == "队伍") {
		for (int i = 0;i < teams.size();i++) {
			QString str = teams[reallyRow[i]].getName();
			if (!str.contains(tempCheck)) {
				ui.totaltable->setRowHidden(i, 1);
			}
		}
	}
	else if (tempType == "男生项目") {
		ui.totaltable->setColumnHidden(totalcolumn, 1);
		for (int i = 0;i < totalcolumn;i++) {
			if (reallyColumn[i] < column1) {
				QString str = boyItems[reallyColumn[i]].getName();
				if (!str.contains(tempCheck)) {
					ui.totaltable->setColumnHidden(i, 1);
				}
			}
			else {
				ui.totaltable->setColumnHidden(i, 1);
			}
		}
	}
	else if (tempType == "女生项目") {
		ui.totaltable->setColumnHidden(totalcolumn, 1);
		for (int i = 0;i < totalcolumn;i++) {
			if (reallyColumn[i] >= column1) {
				//QString str = boyItems[reallyColumn[i]].getName();
				QString str = girlItems[reallyColumn[i]-column1].getName();
				if (!str.contains(tempCheck)) {
					ui.totaltable->setColumnHidden(i, 1);
				}
			}
			else {
				ui.totaltable->setColumnHidden(i, 1);
			}
		}
	}
	else {

	}
}
// 
// 
// 
// 废品
//void page4::sort() {
//	int row = this->myData->getTeamNum();
//	int column1 = this->myData->getItemNum1();
//	int column2 = this->myData->getItemNum2();
//	int totalcolumn = column1 + column2;
//	//vector<boyItem> boyItems = this->myData->getBoyItems();
//	//vector<girlItem> girlItems = this->myData->getGirlItems();
//	//vector<team> teams = this->myData->getTeams();
//	QVector<boyItem> boyItems = this->myData->getBoyItems();
//	QVector<girlItem> girlItems = this->myData->getGirlItems();
//	QVector<team> teams = this->myData->getTeams();
//	QString tempName1 = ui.typeBox->currentText();//类型
//	QString tempName2 = ui.waysBox->currentText();
//	if (tempName1 == "队伍") {
//		/*int acceptItem = 0;*/
//		//寻找目标排序队伍
//		int sortitem;
//		for (int i = 0;i < teams.size();i++) {
//			if (teams[i].getName() == tempName2) {
//				sortitem = i;
//				break;
//			}
//		}
//		for (int i = 0; i < totalcolumn - 1; i++) {
//			bool swapped = false;
//			for (int j = 0; j < totalcolumn - i - 1; j++) {
//				if (itemval[sortitem[j]] < itemval[sortitem[j + 1]]) {
//					swap(sortitem[j], sortitem[j + 1]);
//					swapped = true;
//				}
//			}
//			if (!swapped) break; 
//		}
//
//		
//	}
//	else if (tempName1 == "男生项目") {
//		
//	}
//	else if (tempName1 == "女生项目") {
//		
//	}
//	else if (tempName1 == "总分") {
//		
//	}
//	else {
//		
//	}
//}
//void page4::check() {
//
//}